--
-- Author: mm
-- Date: 2018-03-20 18:07:43
--
-- NewActivityDungeonsSuccessView
-- 活动副本胜利

local Daibi = require("app.public.dao.Daibi")
local IconRender = require("app.widget.renders.IconRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.ActivityWinScene

local rewardNum = 3 -- 奖励个数
local gradeStr = {
	["NONE"] = "",
	["COPPER"] = string.format(" (%s)", L("copper_cup")),
	["SILVER"] = string.format(" (%s)", L("silver_cup")),
	["GOLD"] = string.format(" (%s)", L("gold_cup"))
}
local GradeEnums = {
	["NONE"] = 0,
	["COPPER"] = 1,
	["SILVER"] = 2,
	["GOLD"] = 3
}

function ClassRef:init()
	self._ui.Button_close:addClickEventListener(function()
			executeFunc(self._onOperate,"close_NewActivityDungeonsResultView", self._data)
			self:closeView()
		end)

	self._ui.icon_1:setVisible(false)
	self._ui.icon_3:setVisible(false)
	self._ui.Panel_qq:setVisible(false)
	self._ui["Panel/Panel_qq/wx"]:setVisible(false)
	self._ui["Panel/Panel_qq/qq"]:setVisible(false)
	self._ui["Panel/Panel_qq/vip_super"]:setVisible(false)
	self._ui["Panel/Panel_qq/vip_qq"]:setVisible(false)
end

-- enum GRADE {
-- 	NONE = 0; // 无效评级
-- 	COPPER  = 1; // 铜杯
-- 	SILVER  = 2; // 银杯
-- 	GOLD    = 3; // 金杯
-- }
-- enum ADDTYPE {
-- 	NoAddType = 0; //无
-- 	Tencent  = 1; // 手Q游戏
-- 	WeChat  = 2; // 微信游戏
-- 	NormalVIP    = 3; // 会员
-- 	SuperVIP = 4;//超级会员
-- }
-- message S2C_WorldEventResultNotify {
-- 	int32 id = 1; // 玩法id
-- 	int32 residualRewardTimes = 2; // 剩余奖励次数
-- 	GRADE grade = 3; // 最终评级
-- 	int32 score = 4; // 最终得分
-- 	int32 eventPoint = 5; // 获得活动点数
--  ADDTYPE userAddType = 6;//玩家加成类型
--	int32 userAddNum = 7;//玩家加成百分比
-- }
function ClassRef:refreshContent( dataTemp )
	self._data = dataTemp

	local eventModeConf = GD:queryEventModeById( dataTemp.id )
	local evaluateType = tonumber( eventModeConf.evaluateType )

	local realGrade = ""
	local scoreTemp = tonumber( dataTemp.score or 0 )

	-- 1=高于限定回合
	-- 2=小于限定时间
	-- 3=高于限定血量
	-- 4=灰烬碎片数量
	-- 5=失败方格子数
	if 1 == evaluateType then -- 狮心号角：回合数
		realGrade = string.format( L("LionNotice"), scoreTemp )
	elseif 2 == evaluateType then
		realGrade = string.format( L("ZombieNotice"), scoreTemp )
	elseif 3 == evaluateType then
		realGrade = string.format( L("KingofFightersNotice"), scoreTemp )
	elseif 4 == evaluateType then
		realGrade = string.format( L("lua_code_text_407"), scoreTemp )
	elseif 5 == evaluateType then
		realGrade = string.format( L("ChessWinNotice"), scoreTemp )
	else
		print( " ----------------->>>> 未知活动副本类型 " )
	end
	local gradeTemp = dataTemp.grade or "NONE"
	realGrade = realGrade .. gradeStr[ gradeTemp ]
	-- 通关结果
	self._ui.tips_1:setString(realGrade)

	-- 通关奖杯
	local iconPath = table.concat( { Res.teamUIPath, "team_trophy_icon_", ( 4 - GradeEnums[gradeTemp] ), ".png" } )
	self._ui.icon:loadTexture( iconPath, 1 )

	-- 通关获得的活动点数
	local gotPoint = dataTemp.eventPoint
	local hasPoint = gotPoint > 0
	self._ui.icon_2:setVisible(hasPoint)
	self._ui.tips_img:setVisible(hasPoint)
	self._ui.tips_2:setVisible(hasPoint)
	self._ui.tips_img_3:setVisible(not hasPoint)
	if hasPoint then
		local daibi = Daibi.new()
		daibi:read({tid=91, amount=gotPoint})

		local render = IconRender.create(self._ui.icon_2)
		render:setTipEnable(true)
		render:setTipUnShowOrigin(true)
		render:setData(daibi)
	end
	-- 额外活动加成
	if UD.msdkData:isEnableShowBonus() then
		local extraAdd = dataTemp.userAddNum
		self._ui.Panel_qq:setVisible(true)
		if dataTemp.userAddType == "Tencent" then -- 手Q游戏中心启动
			self._ui["Panel/Panel_qq/qq/num"]:setString("+"..extraAdd.."%")
			self._ui["Panel/Panel_qq/qq"]:setVisible(true)
		elseif dataTemp.userAddType == "WeChat" then -- 微信游戏中心启动
			self._ui["Panel/Panel_qq/wx/num"]:setString("+"..extraAdd.."%")
			self._ui["Panel/Panel_qq/wx"]:setVisible(true)
		elseif dataTemp.userAddType == "SuperVIP" then -- 手Q超级会员
			self._ui["Panel/Panel_qq/vip_super/num"]:setString("+"..extraAdd.."%")
			self._ui["Panel/Panel_qq/vip_super"]:setVisible(true)			
		elseif dataTemp.userAddType == "NormalVIP" then --手Q普通会员
			self._ui["Panel/Panel_qq/vip_qq/num"]:setString("+"..extraAdd.."%")
			self._ui["Panel/Panel_qq/vip_qq"]:setVisible(true)
		else
			self._ui.Panel_qq:setVisible(false)
		end
	end
end

return ClassRef
